import React, { useState, useEffect } from 'react'
import { Form, TreeSelect, message } from 'antd'
import { getTreeData } from '../ajax/index'
import { awaitWrap } from '@js/tool'
const { Item } = Form

// 初始化案由树数据
async function initTreeData (setTreeData) {
  const [e, d] = await awaitWrap(getTreeData())
  if (e) {
    return message.warning(e.message)
  }
  setTreeData(d)
}

function Main () {
  const [treeData, setTreeData] = useState([])
  useEffect(() => {
    initTreeData(setTreeData)
  }, [setTreeData])
  return (
    <Item name='cause_action' label='案由'>
      <TreeSelect
        style={{ width: '100%' }}
        dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
        treeData={treeData}
        placeholder='请选择案由'
        maxTagTextLength={10}
        multiple
        showSearch
      />
    </Item>
  )
}

export default Main
